// Vuex持久化保持方案
import createPersistedState from 'vuex-persistedstate'
// Vuex 自带日志插件
import createLogger from 'vuex/dist/logger'
import {Cache} from '../cache/index'
import { isObject, isString } from '../utils/index'

export default {
    state: {
        userinfo: {},
        subject:{},
		//微信网页授权登录开始
		loginStatus: 0, //登录状态,
		appId:'',//appid 微信网页授权获取appid
		//微信网页授权登录结束
    },
    action: {},
    getters: {
		//微信网页授权登录开始
		login_Status(state) {
			return state.loginStatus
		},
		user_Info(state) {
			return state.userinfo;
		},
		appId(state){
			return state.appId
		},
		//微信网页授权登录结束
	},
    mutations: {
		//微信网页授权登录开始
		setLoginStatus(state, options) {
			state.loginStatus = options
		},
		setAppId(state, options) {
			state.appId = options
		},
		//微信网页授权登录结束
        setSubject(state,payload){
			if (payload && isObject(payload) && payload.subject) {
			    state.subject = payload.subject
			}
        },
		setUserInfo(state, payload) {
		    if (payload && isObject(payload) && payload.userinfo) {
		        state.userinfo = payload.userinfo
		    }
		},
        clearUserInfo(state, payload) {
            state.userinfo = {}
        }
    },
    modules: {},
    plugins: [
        createLogger,
        createPersistedState({
            key: '',
            storage: new Cache()
        })
    ]
}
